﻿using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MyOCR
{
    public partial class SetUp : Form
    {
        public SetUp()
        {
            InitializeComponent();


            //绑定文本框内容
            App_Id_BaiDu_textBox.DataBindings.Add("Text", Program._config, "BaiDu_App_Id");
            Api_Key_BaiDu_textBox.DataBindings.Add("Text", Program._config, "BaiDu_Api_Key");
            Secret_Key_BaiDu_textBox.DataBindings.Add("Text", Program._config, "BaiDu_Secret_Key");

            Pid_SouGou_textBox.DataBindings.Add("Text", Program._config, "SouGou_Pid");
            Key_SouGou_textBox.DataBindings.Add("Text", Program._config, "SouGou_Key");

            App_Id_TengXun_textBox.DataBindings.Add("Text", Program._config, "TengXun_App_Id");
            Secret_Key_TengXun_textBox.DataBindings.Add("Text", Program._config, "TengXun_Secret_Key");
            Secret_Id_TengXun_textBox.DataBindings.Add("Text", Program._config, "TengXun_Secret_Id");

            App_Key_YouDao_textBox.DataBindings.Add("Text", Program._config, "YouDao_App_Key");
            App_Secret_YouDao_textBox.DataBindings.Add("Text", Program._config, "YouDao_App_Secret");

            Recognition.DataBindings.Add("Text", Program._config, "_Recongnition");
            Translate.DataBindings.Add("Text", Program._config, "_Translate");

            AutoTranslation.DataBindings.Add("Checked", Program._config, "_AutoTranslation");
            SelfStart.DataBindings.Add("Checked", Program._config, "_SelfStart");
        }

        private void tabControl1_Selecting(object sender, TabControlCancelEventArgs e)
        {
            switch (e.TabPage.Text)
            {
                case "密钥":
                    ps.Text = "https://ai.baidu.com/tech/ocr/";
                    break;
                default:
                    ps.Text = "";
                    break;
            }
        }

        private void tabControl2_Selecting(object sender, TabControlCancelEventArgs e)
        {
            switch (e.TabPage.Text)
            {
                case "BaiDu":
                    ps.Text = "https://ai.baidu.com/tech/ocr/";
                    break;
                case "SouGou":
                    ps.Text = "https://deepi.sogou.com/";
                    break;
                case "TengXun":
                    ps.Text = "https://cloud.tencent.com/";
                    break;
                case "YouDao":
                    ps.Text = "https://ai.youdao.com/";
                    break;
                default:
                    ps.Text = "";
                    break;
            }
        }

        private void save_btn_Click(object sender, EventArgs e)
        {
            Program._config.Save();
            MessageBox.Show("保存成功", "提示", MessageBoxButtons.OK);
        }

        private void SetUp_FormClosing(object sender, FormClosingEventArgs e)
        {
            Program._config.Save();
        }

        private void SelfStart_Click(object sender, EventArgs e)
        {
            if (SelfStart.Checked)
            {
                string path = Application.ExecutablePath;
                RegistryKey rk = Registry.CurrentUser;
                RegistryKey rk2 = rk.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");
                rk2.SetValue("MyOCR", path);
                rk2.Close();
                rk.Close();
            }
            else
            {
                string path = Application.ExecutablePath;
                RegistryKey rk = Registry.CurrentUser;
                RegistryKey rk2 = rk.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");
                rk2.DeleteValue("MyOCR", false);
                rk2.Close();
                rk.Close();
            }
        }
    }
}
